package com.library.service;

import com.library.dao.BookDAO;
import com.library.model.Book;
import com.library.utils.Validator;

import java.util.List;

public class BookService {
    private BookDAO bookDAO = new BookDAO();

    public List<Book> getAllBooks() {
        return bookDAO.getAllBooks();
    }

    public List<Book> searchBooks(String keyword) {
        return bookDAO.searchBooks(keyword);
    }

    public boolean addBook(Book book) {
        if (!Validator.isPositiveNumber(book.getPrice()) ||
                !Validator.isPositiveNumber(book.getBookTotal()) ||
                !Validator.isPositiveNumber(book.getInventory())) {
            return false;
        }
        return bookDAO.insert(book);
    }

    public boolean updateBook(Book book) {
        if (!Validator.isPositiveNumber(book.getPrice()) ||
                !Validator.isPositiveNumber(book.getBookTotal()) ||
                !Validator.isPositiveNumber(book.getInventory())) {
            return false;
        }
        return bookDAO.update(book);
    }

    public boolean deleteBook(String bookNumber) {
        return bookDAO.delete(bookNumber);
    }

    public Book getBookByNumber(String bookNumber) {
        return bookDAO.getBookByNumber(bookNumber);
    }
}